
var Contact = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_add")[0];
	
				var body = { };
				body.category = form.category.value;
				body.code = form.code.value;
				body.name = form.name.value;
				body.orderby = form.orderby.value;
				body.status = form.status.value;
	
				$(this).dialog("close");
				
				var url = 'info.php?do=Contact.addPost';
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		$.cookie('status_', status);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'info.php?do=Contact.edit&id=' + id;
		var c2 = 'info.php?do=Contact.view&id=' + id;

		var a1 = ['编辑信息', 'url', 'Contact.dialog_edit_', '650x420'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x420'];

		var s = c1 + ", " + c2;

		popup(e, [a1, a2], s);
	},
	
	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
	
				var body = {};
				body.id = form.id.value;
				body.info = form.info.value;
				body.info_id = form.info_id.value;
				
				body.name = form.name.value;
				body.job = form.job.value;
	
				body.tel = form.tel.value;
				body.fax = form.fax.value;
				
				body.mobile = form.mobile.value;
				body.dh = form.dh.value;
				
				body.email = form.email.value;
				body.address = form.address.value;
				
				body.qq = form.qq.value;
				body.skype = form.skype.value;
				
				body.content = form.content.value;
				
				body.orderby = form.orderby.value;
				body.status = form.status.value;
	
				$(this).dialog("close");
	
				var url = 'info.php?do=Contact.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'info.php?do=Contact.delete' + p2;	
		var c2 = 'info.php?do=Contact.ldif' + p2;
			
		var a1 = ['删除信息', 'url', 'Common.list_delete'];
		var a2 = ['导出ldif', 'url', 'Contact.dialog_txt', '650x400'];

		var s = c1 + ", " + c2;

		return popup(e, [a1, a2], s);
	},
	
	dialog_txt: function (url, title, xy) {
		var c = new Array();
		$("input[name^='c_']").each(function() {
			if ($(this).attr("checked")) {
				var s = encodeURIComponent(this.name) + "=" + encodeURIComponent($(this).val());
				c.push(s);
			}
		});
		
		var cc = c.join("&");
		
		var s = url + "&" + cc;
		
		jswin(s, 'jswin', '1024x768');
	}
};
